home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
-
- QPRINTF.C - Quick screen output - Jeff R. Fontanesi, 7/4/89
-
- The routines included here, qprintf and qputch, are fast screen
- output routines. They write directly to the video RAM using
- Turbo C's pokeb function.
-
- Before using these routines, use qp_init to determine which type
- of adapter the system has. This routine sets the global variable
- _vidseg to 0xb000 for monochrome or 0xb800 for CGA or other.
- This is necessary for execution of qprintf and qputch.
-
- The qprintf and qputch routines use nearly the same format as printf
- and putch respectively and behave similarly. The differences are:
-
- * qprintf and qputch allow you to specify the row, column and
- attribute of the string or character to be displayed. The ranges
- of the row and column parameters are 1..25 and 1..80 respectively.
-
- * qprintf and qputch do not change the cursor position.
-
- * qp_init must be invoked once before qprintf and qputch. Side
- effects may result if this is not done.
-
- * Using the escape sequences, \a, \b, \f, \n, \r, \t or \v may
- produce unexpected results because qprintf and qputch write
- directly to video RAM and do not translate these codes.
-
- * You should not try to print outside the screen boundaries or print
- strings longer than 80 characters. Doing so can overwrite
- unexpected areas of memory and may produce side effects. No
- boundary checking is done in these routines.
-
- Syntax of qprintf:
-
- void qprintf(int col, int row, int attr, const char *format[,argument,...]);
-
- int col - the column or x coordinate
- int row - the row or y coordinate
- int attr - the attribute (foreground and background color)
- const char *format[argument,...] - the standard C format string and
- arguments used by printf
-
- Syntax of qputch:
-
- void qputch(int col, int row, int attr, char ch);
-
- int col - the column or x coordinate
- int row - the row or y coordinate
- int attr - the attribute (foreground and background color)
- char ch - the character to be displayed
-
-
- These routines are free for any use. I only ask that if you use them
- or find errors, please let me know. I can be reached as:
-
- Jeff R. Fontanesi
- CompuServe - 74017,1650
- Genie - FONTJR
- Various Southern California BBS's
-
- ****************************************************************************/
-
- #include <stdarg.h>
- #include <stdio.h>
-
- unsigned int _vidseg;
-
- void qp_init(void)
- {
- const long vidmode = 0x00449lu; /* video mode address */
-
- if (*((char far*) vidmode) == 7) /* if video mode is 7 */
- _vidseg = 0xb000u; /* then monochrome */
- else
- _vidseg = 0xb800u; /* else, color */
- }
-
- void qputch(int col, int row, int attr, char ch)
- {
- register int vidofs;
-
- pokeb(_vidseg, vidofs = 160*row+2*col-162, ch); /* poke the char */
- pokeb(_vidseg, ++vidofs, attr); /* poke the attr */
- }
-
- void qprintf(int col, int row, int attr, char *str, ...)
- {
- register int i, x;
- int vidofs;
- char vstr[90];
- va_list vl;
-
- va_start(vl,str); /* get the arguments */
- vsprintf(vstr,str,vl);
- va_end(vl);
- for (i = 0, x = col; vstr[i]; i++, x++)
- {
- pokeb(_vidseg, vidofs = 160*row+2*x-162, vstr[i]); /* poke the char */
- pokeb(_vidseg, ++vidofs, attr); /* poke the attr */
- }
- }
-